﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BO;
using System.Data;

namespace m.Website.Controls.Touch
{
    public partial class NewsDetail : System.Web.UI.UserControl
    {
        protected string urlFB = "";
        string linkSetPage = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            int ZoneID = lib.ZoneID;//zone con
            int ParentID = lib.ParentID;//zone to
            int NewsID = lib.NewsID;
            if (NewsID > 0)
            {
                DataTable dt = BO.News.NewsBO.GetDetailNewsBO(NewsID.ToString());
                if (dt.Rows.Count > 0)
                {
                    string newsID = dt.Rows[0][Const.tbNews.id].ToString();
                    string title = ltTitle.Text = Utils.EnCodeString(dt.Rows[0][Const.tbNews.Title].ToString());
                    string href = Utils.BuildNewsDetail(newsID, dt.Rows[0][Const.tbNews.Url].ToString());
                    string avatar = dt.Rows[0][Const.tbNews.Avatar].ToString();
                    string sapo = ltSapo.Text = dt.Rows[0][Const.tbNews.Sapo].ToString();
                    string sTime = ltTime.Text = "Ngày viết: " + DateTime.Parse(dt.Rows[0][Const.tbNews.DistributionDate].ToString()).ToString("dd/MM/yyyy");
                    string longContent = ltContent.Text = dt.Rows[0][Const.tbNews.longContent].ToString();
                    ZoneID = int.Parse(dt.Rows[0][Const.tbNews.ZoneIdOther].ToString().TrimEnd(','));
                    ParentID = int.Parse(dt.Rows[0][Const.tbNews.ZoneId].ToString());
                    
                    //set title url
                    if (ParentID > 0)
                    {
                        //2 link
                        //link cha
                        DataTable dt1 = BO.News.ZoneBO.GetDetailZoneBO(ParentID.ToString());
                        if (dt1.Rows.Count > 0)
                        {
                            string linkSPage = "/" + dt1.Rows[0][Const.tbZoneNews.url].ToString();
                            ltTitleZone.Text = "<a href=\"" + linkSPage + ".htm\">" + dt1.Rows[0][Const.tbZoneNews.title].ToString() + "</a>";
                        }
                        //link con
                        DataTable dt2 = BO.News.ZoneBO.GetDetailZoneBO(ZoneID.ToString());
                        if (dt1.Rows.Count > 0)
                        {
                            linkSetPage = "/" + dt1.Rows[0][Const.tbZoneNews.url].ToString() + "/" + dt2.Rows[0][Const.tbZoneNews.url].ToString();
                            ltTitleZone.Text += " » <a class=\"last\" href=\"" + linkSetPage + ".htm\">" + dt2.Rows[0][Const.tbZoneNews.title].ToString() + "</a>";
                        }
                    }
                    else
                    {
                        //1 link
                        DataTable dt1 = BO.News.ZoneBO.GetDetailZoneBO(ZoneID.ToString());
                        if (dt1.Rows.Count > 0)
                        {
                            linkSetPage = "/" + dt1.Rows[0][Const.tbZoneNews.url].ToString();
                            ltTitleZone.Text = "<a href=\"" + linkSetPage + ".htm\">" + dt1.Rows[0][Const.tbZoneNews.title].ToString() + "</a>";
                        }
                    }
                }
            }
        }
    }
}